<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-form-pane  layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">状态</label>
                    <div class="layui-input-block">
                        <select name="status">
                            <option value="">全部状态</option>
                            {volist name="status_list" id="v"}
                            <option value="{$key}">{$v}</option>
                            {/volist}
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">操作人</label>
                    <div class="layui-input-block">
                        <input type="text" name="operator" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn" lay-submit lay-filter="{$lay_btn}">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>
                </div>
            </div>
        </div>
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <button class="layui-btn layuiadmin-btn" data-type="add">添加</button>
        </div>

        <div class="layui-card-body">
            <table id="{$lay_table}" lay-filter="{$lay_table}"></table>
            <script type="text/html" id="deTpl">
                <span style="color:darkgreen">{{ d.de_income }}</span>
            </script>
            <script type="text/html" id="ratedTpl">
                <span style="color:red;">{{ d.rated_income }}</span>
            </script>
            <script type="text/html" id="incomeTpl">
                <span style="color:green;">{{ d.income }}</span>
            </script>
            <script type="text/html" id="transferTpl">
                <span style="color:blue;">{{ d.transfer_accounts }}</span>
            </script>
            <script type="text/html" id="setTpl">
                <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit">
                    <i class="layui-icon layui-icon-edit"></i>编辑
                </a>
                <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="export">
                    <i class="layui-icon layui-icon-edit"></i>导出
                </a>
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">
                    <i class="layui-icon layui-icon-delete"></i>删除
                </a>
            </script>
        </div>
    </div>
</div>

<script>
    layui.use(['index', 'admin', 'form', 'table'], function () {
        const $ = layui.$;
        const admin = layui.admin;
        const form = layui.form;
        const table = layui.table;
        form.render();

        table.render({
            elem: '#{$lay_table}',
            url: "{:url('dy/listDianzan')}",
            cols: [
                [
                    {field: 'promotion_time', title: '推广日期', width: 160},
                    {field: 'operator', title: '操作人', width: 100},
                    {field: 'finish', title: '总完成点赞数', width: 160},
                    {field: 'valid', title: '总生效点赞数', width: 160},
                    {field: 'income', title: '推广人总收益', width: 160, toolbar: '#incomeTpl'},
                    {field: 'ac_income', title: '账面收益', width: 160},
                    {field: 'de_income', title: '扣除推广后的收益', width: 160, toolbar: '#deTpl'},
                    {field: 'rated_income', title: '平分收益', width: 160, toolbar: '#ratedTpl'},
                    {field: 'transfer_accounts', title: '需转账金额', width: 160, toolbar: '#transferTpl'},
                    {field: 'status_text', title: '状态', width: 100},
                    {field: 'comment', title: '备注'},
                    {title: '操作', width: 220, align: 'center', fixed: 'right', toolbar: '#setTpl'}
                ]
            ],
            page: true,
            limit: 50,
            cellMinWidth: 150,
            text: '对不起，加载出现异常！'
        });

        form.on('submit({$lay_btn})', function (data) {
            table.reload('{$lay_table}', {
                where: data.field,
                page: {
                    curr: 1
                }
            });
        });

        //事件
        const active = {
            add: function () {
                const index = layer.open({
                    type: 2,
                    title: '添加点赞',
                    content: "{:url('dy/dianzanForm')}",
                    maxmin: true,
                    area: ['550px', '550px']
                });
                layer.full(index);
            }
        };

        //监听工具条
        table.on('tool({$lay_table})', function (obj) {
            const data = obj.data;
            if (obj.event === 'del') {
                layer.confirm('确定删除吗？', function (index) {
                    admin.req({
                        url: "{:url('dy/delDianzan')}",
                        data: {
                            id: data.id
                        },
                        done: function (res) {
                            layui.table.reload('{$lay_table}');
                        }
                    });
                    layer.close(index);
                });
            } else if (obj.event === 'edit') {
                const index = layer.open({
                    type: 2,
                    title: '编辑点赞',
                    content: "{:url('dy/dianzanForm')}?id=" + data.id,
                    maxmin: true,
                    area: ['550px', '550px']
                });
                layer.full(index);
            } else if (obj.event === 'export') {
                const url = "{:url('dy/exportDianzan')}?id=" + data.id;
                window.open(url);
            }
        });

        $('.layui-btn.layuiadmin-btn').on('click', function () {
            const type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });
</script>
